package com.lovo.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.lovo.bean.dto.UserDTO;
import com.lovo.service.UserService;
import com.lovo.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/login")
public class LoginController extends HttpServlet {
    private UserService userService = new UserServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String pwd = req.getParameter("pwd");
        System.out.println("username:" + username + "pwd:" + pwd);
        UserDTO userDTO = userService.login(username,pwd);
        ObjectMapper mapper = new ObjectMapper();

//        System.out.println(mapper.writeValueAsString(userDTO));
        resp.getWriter().println(mapper.writeValueAsString(userDTO));
    }
}
